CREATE TRIGGER trg_Import_Insert
ON  tb_Room_Detail_Inport
FOR INSERT
AS
UPDATE [tb_Order_Buy_Detail] 
SET [tb_Order_Buy_Detail].Order_Detail_Quality = [tb_Order_Buy_Detail].Order_Detail_Quality - INSERTED.Quality
FROM [tb_Order_Buy_Detail] INNER JOIN INSERTED ON [tb_Order_Buy_Detail].Order_Buy_Detail_Id = INSERTED.Order_Buy_Detail_Id
--------------------------
CREATE trigger trg_Import_Update_Quality
on tb_Room_Detail_Inport
for update
as
if update(Quality)
update [tb_Order_Buy_Detail]  set [tb_Order_Buy_Detail] .Order_Detail_Quality=[tb_Order_Buy_Detail].Order_Detail_Quality-(inserted.Quality-deleted.Quality)
from (deleted inner join inserted on deleted.Order_Buy_Detail_Id=inserted.Order_Buy_Detail_Id) inner join [tb_Order_Buy_Detail] on [tb_Order_Buy_Detail].Order_Buy_Detail_Id=deleted.Order_Buy_Detail_Id 
--------------------------
CREATE trigger trg_Import_Delete
on tb_Room_Detail_Inport
for delete
as
update [tb_Order_Buy_Detail] set [tb_Order_Buy_Detail].Order_Detail_Quality=[tb_Order_Buy_Detail].Order_Detail_Quality+deleted.Quality
from [tb_Order_Buy_Detail] inner join deleted on [tb_Order_Buy_Detail].Order_Buy_Detail_Id=deleted.Order_Buy_Detail_Id
--------------------------
SELECT * FROM [tb_Employee]
SELECT * FROM [tb_Order_Buy]
SELECT * FROM [tb_Order_Buy_Detail]
SELECT * FROM [tb_Room_Detail_Inport]
--SELECT * FROM [tb_Room_Detail_Inport]
delete from [tb_Room_Detail_Inport] where id =13
--------------------------
insert into [tb_Room_Detail_Inport]
(Order_Buy_Detail_Id,Materials_Id,Quality,TotalPrice) 
values(51,1,11,11 * 1000)
update [tb_Room_Detail_Inport] set Quality = 10,TotalPrice =10 * 1000
where Id =1

--@Order_Buy_Detail_Id
--@Materials_Id
--@Quality
--@Price
--@User_Id
--@Status

sp_ImportOrder_Insert_Temp 51,1,2,1000,1,0
go
sp_ImportOrderTemp
sp_ImportOrder
sp_tb_Room_Detail_Import